package cn.tedu._05mvcboot03.common.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import springfox.documentation.spring.web.json.Json;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "状态码")
    private Integer state;
    @ApiModelProperty(value = "提示消息")
    private String message;
    @ApiModelProperty(value = "返回数据")
    private Object data;

    public JsonResult(StatusCode statusCode){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
    }
    public JsonResult(StatusCode statusCode,Object data){
        this.state = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    public static JsonResult ok(){
        return ok(null);
    }
    public static JsonResult fail(Object data){
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
}
